package ar.com.PanteraRosa;
import org.json.JSONException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import ar.com.PanteraRosa.Business.UserController;
import ar.com.PanteraRosa.Common.Conf;

public class LoginUserActivity extends Activity {
	
	private EditText UserNick;
	private EditText UserPassword;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
		setTitle(R.string.app_name);
		
		UserNick = (EditText) findViewById(R.id.TxtUsuario);
		UserPassword = (EditText) findViewById(R.id.TxtPassword);
    }

    public void btnLogin_OnClick(View vista) throws JSONException, InterruptedException{
    	
    	Intent intent = new Intent();
    	intent.setClass(this, HomeUserActivity.class);
    	UserNick = (EditText) findViewById(R.id.TxtUsuario);
    	UserPassword = (EditText) findViewById(R.id.TxtPassword);
    	   	
    	UserController userController = new UserController(this);
    	userController.login(UserNick.getText().toString(), UserPassword.getText().toString());
    	
    	if (Conf.getInstance().isLogged())
    	    startActivity(intent);
    	else
    	{
    		AlertDialog.Builder alert = new AlertDialog.Builder(this);

    		alert.setTitle("Error!");
    		alert.setMessage("Llamalo a Fede.");

    		alert.setPositiveButton("Ok",null);
    		alert.show();
    	}
    }
    
    public void btnNewUser_OnClick(View vista) throws JSONException{
    	Intent intent = new Intent();
    	intent.setClass(this, EditUserActivity.class);
    	startActivity(intent);
    }
       
}

